﻿
Partial Class WebForm_ManageTrainingCourse_AddTrainingCourse
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.FV.InsertItemTemplate = Me.FV.ItemTemplate
        Me.FV.EditItemTemplate = Me.FV.ItemTemplate
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

        End If
    End Sub

#Region "Delegate"

    Public Event Saving(ByVal sender As Object, ByVal e As EventArgs)

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

        If DataAccessMode = FormViewMode.Insert Then
            FV.InsertItem(True)

        ElseIf DataAccessMode = FormViewMode.Edit Then
            FV.UpdateItem(True)

        End If

        RaiseEvent Saving(Me, New EventArgs)

    End Sub

#End Region

End Class

Partial Class WebForm_ManageTrainingCourse_AddTrainingCourse

    Public Sub InitData(ByVal strId As String)

        KeyId = strId

        If strId = 0 Then
            '新增
            Me.DataAccessMode = FormViewMode.Insert
            Me.FV.ChangeMode(FormViewMode.Insert)

        Else
            '編輯
            Me.DataAccessMode = FormViewMode.Edit
            Me.FV.ChangeMode(FormViewMode.Edit)

            ObjectDataSource1.SelectParameters("Id").DefaultValue = KeyId

            FV.DataSourceID = ObjectDataSource1.ID
            FV.DataBind()

        End If

    End Sub

#Region "Property"

    Public Property DataAccessMode() As FormViewMode
        Get
            If ViewState("DataAccessMode") Is Nothing Then
                Return FormViewMode.Insert
            End If

            Return ViewState("DataAccessMode")
        End Get
        Set(ByVal value As FormViewMode)
            ViewState("DataAccessMode") = value
        End Set

    End Property

    Public Property KeyId() As String
        Get
            Return ViewState("KeyId").ToString()
        End Get
        Set(ByVal value As String)
            ViewState("KeyId") = value
        End Set

    End Property

#End Region

End Class
